<?php

namespace app\admin\model;

use app\common\model\BaseModel;


class Order extends BaseModel
{

    

    

    // 表名
    protected $name = 'order';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'refundTime_text',
        'visitTime_text',
        'expireTime_text',
        'fundAccount_type_text',
        'status_text',
        'type_text'
    ];
    

    
    public function getFundaccountTypeList()
    {
        return ['1' => __('Fundaccount_type 1'), '2' => __('Fundaccount_type 2')];
    }

    public function getStatusList()
    {
        return ['0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2'), '3' => __('Status 3'), '4' => __('Status 4')];
    }

    public function getTypeList()
    {
        return ['0' => __('Type 0'), '1' => __('Type 1'), '2' => __('Type 2')];
    }


    public function getRefundtimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['refundTime']) ? $data['refundTime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getVisittimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['visitTime']) ? $data['visitTime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getExpiretimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['expireTime']) ? $data['expireTime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getFundaccountTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['fundAccount_type']) ? $data['fundAccount_type'] : '');
        $list = $this->getFundaccountTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    protected function setRefundtimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setVisittimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setExpiretimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    /**
     * 根据订单编号查询
     *
     * @param [type] $orderon
     * @return object
     */
    public function getFindOrderId($orderon,$type){
        return $this->where('orderId',$orderon)->where('type',$type)->find();
    }
    /**
     * 根据订单编号查询
     *
     * @param [type] $orderon
     * @return object
     */
    public function getFindOrderOn($orderon,$type){
        return $this->where('order_no',$orderon)->where('type',$type)->find();
    }
    /**
     * 根据订单编号查询
     *
     * @param [type] $orderon
     * @return object
     */
    public function getFindpolicyNo($policyNo,$type){
        return $this->where('policy_no',$policyNo)->where('type',$type)->find();
    }


}
